/*
 * Copyright (C) 2017 Fromentin Xavier
 *
 * This file is part of GDOB.
 *
 * GDOB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GDOB is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.grimdawnofflinebuilder.util.config

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File

/**
 * Class to stock preferences from preferences.json
 *
 * @property installDir installation folder of GDOB
 * @property grimDawnDir installation folder of Grim Dawn
 */
data class Preferences( val installDir: String, val grimDawnDir: String )

/**
 * Class to stock the name of needed items' folders
 */
data class ItemsFilesFolder( val gear: List<String> )

/**
 * Class to stock configuration properties needed to read records files from recordsReader.json
 *
 * @property recordsDir         Name of the folder containing the database records
 * @property itemDir            Name of the folder containing the database records of the items
 * @property itemsFilesFolders  Name of relevant sub-folders in the items folder
 */
data class RecordsReaderConfig( val recordsDir: String, val itemDir: String, val itemsFilesFolders: ItemsFilesFolder )

/**
 * Class to access available configurations
 */
class GDOBConfig {

    companion object {

        /**
         * Preferences
         */
        val preferences: Preferences

        /**
         * Configuration for the records' reader
         */
        val recordsReaderConfig: RecordsReaderConfig

        /**
         * Init
         */
        init {
            val mapper = jacksonObjectMapper()

            // Read preferences
            preferences = mapper.readValue<Preferences>( File( "conf/preferences.json" ) )

            // Read records' reader config
            recordsReaderConfig = mapper.readValue<RecordsReaderConfig>( File( "conf/recordsReader.json" ) )
        }
    }

}